import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.Scanner;

public class WebTest {
    private static ChromeDriver chromeDriver;
    public static void main(String[] args) throws InterruptedException {
        open();

        WebDriverWait wd = new WebDriverWait(chromeDriver, 60);
		/*WebDriverWait wd = new WebDriverWait(chromeDriver, 20);
		wd.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".ivu-btn ivu-btn-primary ivu-btn-long")));*/
        //Thread.sleep(3000);
        wd.until(ExpectedConditions.visibilityOfElementLocated((By.xpath("//*[@id=\"app\"]/div/div/div/div[2]/div/div/div[2]/div/div/div[4]/button/span"))));
        //运营审批，点击进入
        chromeDriver.findElements(By.xpath("//button[@class='ivu-btn ivu-btn-primary ivu-btn-long']")).get(1).click();
        //chromeDriver.findElementsByXPath("//button[@class='ivu-btn ivu-btn-primary ivu-btn-long']").get(1).click();
        System.out.println("运营审批，点击进入");
        //*[@id="app"]/div/div/div/div[2]/div[1]/div[1]/div/ul/li[2]/div/i

        //停顿10秒
        //Thread.sleep(10000);
        //chromeDriver.navigate().back();
//*[@id="app"]/div/div/div/div[2]/div[1]/div[1]/div/ul/li[2]/ul/li[1]
        wd.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"app\"]/div/div/div/div[2]/div[1]/div[1]/div/ul/li[2]/ul/li[1]")));
        //资源目录编目审核，开始点击
        chromeDriver.findElements(By.xpath("//li[@class='ivu-menu-item']")).get(6).click();
        //chromeDriver.findElementsByXPath("//li[@class='ivu-menu-item']").get(6).click();
        System.out.println("资源目录编目审核，已点击");

        Thread.sleep(3000);
        //wd.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"app\"]/div/div/div/div[2]/div[2]/div/div/div[2]/div[1]/div/div/div/div/div[3]")));

        //点击资源目录修改工单
        chromeDriver.findElement(By.xpath("//*[@id=\"app\"]/div/div/div/div[2]/div[2]/div/div/div[2]/div[1]/div/div/div/div/div[3]")).click();
        //chromeDriver.findElementByXPath("//*[@id=\"app\"]/div/div/div/div[2]/div[2]/div/div/div[2]/div[1]/div/div/div/div/div[3]").click();
        System.out.println("资源目录修改工单已点击");

        //Thread.sleep(5000);
        wd.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"app\"]/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[2]/div/div/div/div[2]/div/div/div[2]/table/tbody/tr[1]/td[15]/div/div/button")));



        for (int i=0;i<200;i++){
            //点击第一条处理
            chromeDriver.findElement(By.xpath("//*[@id=\"app\"]/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[2]/div/div/div/div[2]/div/div/div[2]/table/tbody/tr[1]/td[15]/div/div/button")).click();
            //chromeDriver.findElementByXPath("//*[@id=\"app\"]/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[2]/div/div/div/div[2]/div/div/div[2]/table/tbody/tr[1]/td[15]/div/div/button").click();
            System.out.println("第一条处理，已点击");
            //*[@id="app"]/div/div/div/div[2]/div[2]/div/div/div[8]/div/button/span
            wd.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"app\"]/div/div/div/div[2]/div[2]/div/div/div[8]/div/button/span")));

            //点击提交
            chromeDriver.findElement(By.xpath("//*[@id=\"app\"]/div/div/div/div[2]/div[2]/div/div/div[8]/div/button/span")).click();
            //chromeDriver.findElementByXPath("//*[@id=\"app\"]/div/div/div/div[2]/div[2]/div/div/div[8]/div/button/span").click();
            System.out.println("点击提交");

            //Thread.sleep(3000);
            wd.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[21]/div[2]/div/div/div[3]/div/button[2]")));


            chromeDriver.findElement(By.xpath("/html/body/div[21]/div[2]/div/div/div[3]/div/button[2]")).click();
            //chromeDriver.findElementByXPath("/html/body/div[21]/div[2]/div/div/div[3]/div/button[2]").click();
            System.out.println("点击确定");
            //Thread.sleep(20000);

            wd.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"app\"]/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[2]/div/div/div/div[2]/div/div/div[2]/table/tbody/tr[1]/td[15]/div/div/button")));
            //*[@id="app"]/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[2]/div/div/div/div[2]/div/div/div[2]/table/tbody/tr[1]/td[15]/div/div/button/span

        }


    }

    public static void open(){

        System.setProperty("webdriver.chrome.driver", "D:\\Learn\\WorkSpace\\JiangBeiWork\\Selenium\\src\\main\\resources\\chromedriver.exe");
        chromeDriver = new ChromeDriver();
        chromeDriver.get("http://10.19.179.28");
        chromeDriver.manage().window().maximize();
        System.out.println("请输入验证码：");
        Scanner input = new Scanner(System.in);
        String str = input.next();
        chromeDriver.findElement(By.tagName("input")).sendKeys("jbqdsjfzfwzx" + "\t" + "jbdsjgl_820\t" + str);
        chromeDriver.findElement(By.cssSelector(".ivu-btn.ivu-btn-primary.ivu-btn-long")).click();
    }
}
